import 'package:lib_common/lib_common.dart';

class RouteObserver extends NavigatorObserver {
  @override
  void didPop(Route route, Route? previousRoute) {
    super.didPop(route, previousRoute);
    AppManager.getInstance().currentRoute = previousRoute?.settings.name;
    AppManager.getInstance().previousRoute = route.settings.name;
    LogUtils.v("didPop->previousRoute:${previousRoute?.settings.name}, route:${route.settings.name}");
  }

  @override
  void didPush(Route route, Route? previousRoute) {
    super.didPush(route, previousRoute);
    AppManager.getInstance().currentRoute = route.settings.name;
    AppManager.getInstance().previousRoute = previousRoute?.settings.name;
    LogUtils.v("didPush->previousRoute:${previousRoute?.settings.name}, route:${route.settings.name}");
  }

  @override
  void didRemove(Route route, Route? previousRoute) {
    super.didRemove(route, previousRoute);
    AppManager.getInstance().currentRoute = previousRoute?.settings.name;
    LogUtils.v("didRemove->previousRoute:${previousRoute?.settings.name}, route:${route.settings.name}");
  }

  @override
  void didReplace({Route? newRoute, Route? oldRoute}) {
    super.didReplace(newRoute: newRoute, oldRoute: oldRoute);
    AppManager.getInstance().currentRoute = newRoute?.settings.name;
    AppManager.getInstance().previousRoute = oldRoute?.settings.name;
    LogUtils.v("didReplace->oldRoute:${oldRoute?.settings.name}, newRoute:${newRoute?.settings.name}");
  }

  @override
  void didStartUserGesture(Route route, Route? previousRoute) {
    super.didStartUserGesture(route, previousRoute);
    AppManager.getInstance().currentRoute = previousRoute?.settings.name;
    AppManager.getInstance().previousRoute = route.settings.name;
    LogUtils.v("didStartUserGesture->previousRoute:${previousRoute?.settings.name}, route:${route.settings.name}");
  }

  @override
  void didStopUserGesture() {
    super.didStopUserGesture();
    LogUtils.v("didStopUserGesture");
  }
}
